package my.sample.quartz.custom;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.GroupMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CustomTemplate {

	private static Logger log = null;
	
	public static void main(String[] args) throws SchedulerException, InterruptedException {

		log = LoggerFactory.getLogger(CustomTemplate.class);
		
		SchedulerFactory fact = new StdSchedulerFactory();
		Scheduler scheduler = fact.getScheduler();
		System.out.println("scheduler name: " + scheduler.getSchedulerName());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		scheduler.start();
		System.out.println(scheduler.hashCode());
		
		// job
		JobDetail job = newJob(SimpleJob.class).withIdentity("myFirst", "myGroup").build();
		JobDetail job1 = newJob(SimpleJob.class).withIdentity("mySecond", "myGroup").build();
		
		// trigger
		CronTrigger trigger = newTrigger().withIdentity("myFirst", "myGroup").withSchedule(cronSchedule(  "0 30 17 21 10 ? 2013")).build();
		CronTrigger trigger1 = newTrigger().withIdentity("mySecond", "myGroup").withSchedule(cronSchedule("0 32 17 21 10 ? 2013")).build();
				
		scheduler.scheduleJob(job, trigger);
		scheduler.scheduleJob(job1, trigger1);
		log.info("Jobs are scheduled, waiting....");
		
	}

}
